﻿ @using PayrollExpress.Helpers;
@using PayrollExpress.Models;
@model EmployeeContractAddEditModel

@Html.Partial("_BreadCrumb", Model.BreadCrumb)

@using (Html.BeginForm(BaseHelper.PageAddEditSave.EmployeeContractSave.ToString(), Model.ControllerName, FormMethod.Post, new { id = "saveForm" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>

        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-8">
                    <div class="ibox float-e-margins">

                        <div class="ibox-title">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>@MasterfileHelper.ListHeaders.EmployeeCode.ToDescription()</th>
                                        <th>@MasterfileHelper.ListHeaders.EmployeeName.ToDescription()</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>
                                            @Html.DisplayFor(m => Model.EmployeeCode)
                                            @Html.HiddenFor(m => Model.EmployeeCode)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(m => Model.EmployeeName)
                                            @Html.HiddenFor(m => Model.EmployeeName)
                                        </td>
                                    </tr>
                                </tbody>
                            </table>

                            <div>@Html.ValidationMessageFor(m => m.Type.EmploymentTypeID)</div>
                            <div>@Html.ValidationMessageFor(m => m.Type.StartDate)</div>
                            <div>@Html.ValidationMessageFor(m => m.Type.RateTypeID)</div>
                            <div>@Html.ValidationMessageFor(m => m.Type.Rate)</div>

                        </div>

                        <div class="ibox-content">
                            <table class="table table-bordered table-striped table-hover">
                                <tr>
                                    <th>@Html.LabelFor(m => m.Type.EmploymentTypeID)</th>
                                    <td>
                                        @Html.HiddenFor(m => m.Type.ID)
                                        @Html.HiddenFor(m => m.Type.EmployeeCode)
                                        @Html.DropDownListFor(m => m.Type.EmploymentTypeID, Model.EmploymentTypes, new { @class = "form-control input" })
                                    </td>
                                </tr>
                                <tr>
                                    <th>@Html.LabelFor(m => m.Type.StartDate)</th>
                                    <td>@Html.TextBoxFor(m => m.Type.StartDate, "{0:MM/dd/yyyy}", new { @class = "form-control input datepicker", @placeholder = "mm/dd/yyyy" })</td>
                                </tr>
                                <tr>
                                    <th>@Html.LabelFor(m => m.Type.EndDate)</th>
                                    <td>@Html.TextBoxFor(m => m.Type.EndDate, "{0:MM/dd/yyyy}", new { @class = "form-control input datepicker", @placeholder = "mm/dd/yyyy" })</td>
                                </tr>
                                <tr>
                                    <th>@Html.LabelFor(m => m.Type.RateTypeID)</th>
                                    <td>@Html.DropDownListFor(m => m.Type.RateTypeID, Model.RateTypes, new { @class = "form-control input" })</td>
                                </tr>
                                <tr>
                                    <th>@Html.LabelFor(m => m.Type.Rate)</th>
                                    <td>@Html.TextBoxFor(m => m.Type.Rate, "{0:#,###,##0.00}", new { @class = "form-control input", @onchange = "FormatMe(this)" })</td>
                                </tr>
                                <tr>
                                    <th>@Html.LabelFor(m => m.Type.IsCurrent)</th>
                                    <td>@Html.CheckBoxFor(m => m.Type.IsCurrent)</td>
                                </tr>
                            </table>
                            <p></p>
                            <button type="submit" id="btnSave" class="btn btn-primary" name="command" value=@Model.PageAction>@BaseHelper.PageAction.Save.ToDescription()</button>
                            <button type="submit" id="btnCancel" class="btn btn-primary cancel" name="command" value="@BaseHelper.PageAction.Cancel.ToString()">@BaseHelper.PageAction.Cancel.ToDescription()</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </fieldset>
}

@section Styles {
    @Styles.Render("~/plugins/dataPickerStyles")
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/plugins/dataPicker")

    <script type="text/javascript">

        $(document).ready(function () {
            $(window).keydown(function (event) {
                if (event.keyCode == 13) {
                    event.preventDefault();
                    return false;
                }
            });

            $('.datepicker').datepicker({
                todayBtn: "linked",
                keyboardNavigation: false,
                forceParse: false,
                calendarWeeks: true,
                format: 'mm/dd/yyyy',
                autoclose: true

            });
        });

        function FormatMe(me) {
            var val = $(me).val().replace(',', '').replace(',', '').replace(',', '');

            if (isNaN(parseFloat(val)))
                val = 0.00;

            var decimalFormat = parseFloat(val).toFixed(2);
            var commaFormat = FormatNumber(decimalFormat);

            $(me).val(commaFormat);
        }

        function FormatNumber(nStr) {
            nStr += '';
            var x = nStr.split('.');
            var x1 = x[0];
            var x2 = x.length > 1 ? '.' + x[1] : '';
            var rgx = /(\d+)(\d{3})/;
            while (rgx.test(x1)) {
                x1 = x1.replace(rgx, '$1' + ',' + '$2');
            }
            return x1 + x2;
        }

    </script>
}